<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="创建时间" prop="createDate">
        <el-date-picker clearable
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="发布时间" prop="a101">
        <el-input
          v-model="queryParams.a101"
          placeholder="请输入发布时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="行业分类" prop="categoryName">
        <el-input
          v-model="queryParams.categoryName"
          placeholder="请输入行业分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:recordrandom:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:recordrandom:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordrandomList" @selection-change="handleSelectionChange">
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="a101" />
      <el-table-column label="行业分类" align="center" prop="categoryName" />
      <el-table-column label="随机数量" align="center" prop="randomNum" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleShow(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:recordrandom:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:recordrandom:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改随机记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发布时间" prop="a101">
          <el-input v-model="form.a101" placeholder="请输入发布时间" />
        </el-form-item>
        <el-form-item label="是否参与过抽取" prop="isRandom">
          <el-input v-model="form.isRandom" placeholder="请输入是否参与过抽取" />
        </el-form-item>
        <el-form-item label="行业分类" prop="categoryName">
          <el-input v-model="form.categoryName" placeholder="请输入行业分类" />
        </el-form-item>
        <el-form-item label="随机数量" prop="randomNum">
          <el-input v-model="form.randomNum" placeholder="请输入随机数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

        <!-- 随机记录 -->
    <el-dialog v-loading="loadingrandom" :title="title" :visible.sync="openRandom" width="1000px" append-to-body>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleRandomExport"
        >导出</el-button>
      </el-col>
      <el-table :data="standardrandomList" >
      <el-table-column label="标准号" align="center" prop="a100" />
      <el-table-column label="标准名称" align="center" prop="a298" />
      <el-table-column label="标准类型" align="center" prop="a850" />
      <el-table-column label="分类名" align="center" prop="categoryName" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="发布日期" align="center" prop="a101" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.a101, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="标准状态" align="center" prop="a200" >
        <template slot-scope="scope">
          <span class="statusyx" v-if="scope.row.a200=='现行有效'">{{scope.row.a200}}</span>
          <span class="statusfz" v-if="scope.row.a200=='企业自行废止'">{{scope.row.a200}}</span>
        </template>
      </el-table-column>
      <el-table-column label="法人" align="center" prop="legalperson" />
      <el-table-column label="电子文本" align="center" prop="a893" >
        <template slot-scope="scope">
          <a class="txtDown" v-if="scope.row.a893!=null" :href="scope.row.a893" target="_blank" ><el-tag>电子文本</el-tag></a>
        </template>
      </el-table-column>
      <el-table-column label="是否参与抽取" align="center" prop="isRandom" >
        <template slot-scope="scope">
          <span v-if="scope.row.isRandom=='0'">否</span>
          <span v-if="scope.row.isRandom=='1'">是</span>
        </template>
      </el-table-column>
      <el-table-column label="问题" align="center" prop="remark" />
    </el-table>
    </el-dialog>

  </div>
</template>

<script>
import { listRecordrandom, getRecordrandom, delRecordrandom, addRecordrandom, updateRecordrandom, listByRecord } from "@/api/system/recordrandom";

export default {
  name: "Recordrandom",
  data() {
    return {
      // 遮罩层
      loading: true,
      loadingrandom: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 随机记录表格数据
      recordrandomList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openRandom: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createDate: null,
        a101: null,
        isRandom: null,
        categoryName: null,
        randomNum: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      recordad:{

      },
      //随机标准
      standardrandomList:null
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询随机记录列表 */
    getList() {
      this.loading = true;
      listRecordrandom(this.queryParams).then(response => {
        this.recordrandomList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createDate: null,
        a101: null,
        isRandom: null,
        categoryName: null,
        randomNum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加随机记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecordrandom(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改随机记录";
      });
    },
    /** 查看详情 */
    handleShow(row){
      this.openRandom = true;
      this.title = "详情";
      this.recordad = {
        id:row.id
      }
      listByRecord(this.recordad).then(response=>{
        this.standardrandomList = response.data
      })
    },
    /**导出 */
    handleRandomExport(){
      this.download('system/recordrandom/randomStandardDown', {
        ...this.recordad
      }, `standard_${new Date().getTime()}.xlsx`)
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecordrandom(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecordrandom(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除随机记录编号为"' + ids + '"的数据项？').then(function() {
        return delRecordrandom(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/recordrandom/export', {
        ...this.queryParams
      }, `recordrandom_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
